<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"    
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:g="http://graphml.graphdrawing.org/xmlns"
    exclude-result-prefixes="xs" version="2.0">
    <xd:doc xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl" scope="stylesheet">
        <xd:desc>
            <xd:p><xd:b>Created on:</xd:b> Jun 28, 2010</xd:p>
            <xd:p><xd:b>Author:</xd:b> Cionzo</xd:p>
            <xd:p></xd:p>
        </xd:desc>
    </xd:doc>
    <xsl:template match="g:graphml">
        
        <graphml xmlns="http://graphml.graphdrawing.org/xmlns"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns file:/C:/Users/Cionzo/workspace/DiGraph/xml/xsd/graphml.xsd">
            <xsl:apply-templates/>
        </graphml>
        
    </xsl:template>
    <xsl:template  match="g:graph">
        <xsl:element name="graph" namespace="http://graphml.graphdrawing.org/xmlns">
            <xsl:call-template name="copiaAttrib"/> 
            
            <xsl:element name="desc" namespace="http://graphml.graphdrawing.org/xmlns">
                <xsl:value-of select="./g:desc/text()"/>                
            </xsl:element> 
            
            <xsl:element name="nodeCollection" namespace="http://graphml.graphdrawing.org/xmlns">
                <xsl:for-each select="./g:node">
                    
                    <xsl:element name="node" namespace="http://graphml.graphdrawing.org/xmlns">
                        <xsl:call-template name="copiaAttrib"></xsl:call-template>
                        <xsl:attribute name="x" >
                            <xsl:value-of select=".//*/@x"/>
                        </xsl:attribute>
                        <xsl:attribute name="y" >
                            <xsl:value-of select=".//*/@y"/>
                        </xsl:attribute>
                    </xsl:element>
                </xsl:for-each>
            </xsl:element>
            
            <xsl:element name="edgeCollection" namespace="http://graphml.graphdrawing.org/xmlns">
                <xsl:for-each select="./g:edge">
                    <xsl:element name="edge" namespace="http://graphml.graphdrawing.org/xmlns">
                        <xsl:call-template name="copiaAttrib"/>
                    </xsl:element>
                </xsl:for-each>
            </xsl:element>
        </xsl:element>
        
    </xsl:template>
    
    <xsl:template name="copiaAttrib">
        <xsl:for-each select="./attribute::node()" >
            <xsl:copy/>
        </xsl:for-each>
    </xsl:template>
   
</xsl:stylesheet>
